/**
 * Copyright (c) 2023 murenchao
 * taomu is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *       http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package cool.taomu.toolkit.jsch.provider

import com.google.gson.reflect.TypeToken
import com.google.inject.Inject
import com.google.inject.name.Named
import cool.taomu.toolkit.entity.TaomuConfig
import cool.taomu.toolkit.jsch.entity.JschConfigEntity
import cool.taomu.toolkit.jsch.service.JschConnection
import java.util.Hashtable
import java.util.List
import java.util.Map
import javax.inject.Provider
import org.eclipse.xtend.lib.annotations.Accessors

@Accessors
@Deprecated
class JschProvider implements Provider<Map<String, JschConnection>> {

	@Inject(optional=true)
	@Named("taomu.jsch")
	TaomuConfig config;

	override get() {
		val configMap = <String, JschConnection>newHashMap();
		if (config !== null) {
			var list = config.get(new TypeToken<List<JschConfigEntity>>() {
			})
			list.forEach [
				var ds = new JschConnection(it.host, it.username, it.password, it.port);
				ds.proxy = it.proxy
				ds.sshconfig = new Hashtable();
				configMap.put(it.name, ds)
			]
		}
		return configMap;
	}

}
